package org.csu.myPetStore.web.servlet;

import org.csu.myPetStore.domain.Order;
import org.csu.myPetStore.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class ViewOrderFromMyCountServlet extends HttpServlet {

    private static final String VIEW_ORDER = "/WEB-INF/jsp/order/ViewOrder.jsp";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int orderId = Integer.parseInt(req.getParameter("orderId"));

        HttpSession session = req.getSession();
        OrderService service = new OrderService();
        Order order = service.getOrder(orderId);
        session.setAttribute("order",order);

        req.getRequestDispatcher(VIEW_ORDER).forward(req,resp);
    }

}
